package com.touch.graphingutil;

import java.awt.Color;
import java.awt.Graphics;

public class JBarGraph extends JGraph
{
	private static final long serialVersionUID = 2619175047524361803L;
	private int position;
	private int increment;
	
	public JBarGraph(String title, int min, int max) 
	{
		super(title, min, max);
	}
	public void paintComponent(Graphics g) 
	{
		super.paintComponent(g);
		this.increment = (this.right - this.left)/(this.items.size());
	    this.position = this.left;
		
	    final Color temp = g.getColor();
	    for (int i = 0; i < this.items.size(); i++) 
	    {
	    	final GraphItem item = (GraphItem)items.elementAt(i);
		    final int adjustedValue = bottom - (((item.value - min)*(bottom - top))/(max - min));
		    
		    g.drawString(item.title, position + (increment -
		    fm.stringWidth(item.title))/2, adjustedValue - 2);
		    g.setColor(item.color);
		    g.fillRect(position, adjustedValue, increment, bottom - adjustedValue);
		    this.position+=increment;
		    g.setColor(temp);
	    }
	}	
}
